package com.jinbei.restController;

import com.alibaba.fastjson.JSONObject;
import com.jinbei.common.base.BaseRedisService;
import com.jinbei.common.base.SocketBase;
import com.jinbei.common.socket.MessageWebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * Created by lucky on 2018/7/10.
 */
@RestController
public class TestController {

    @Autowired
    private MessageWebSocket messageWebSocket;

    @Autowired
    private BaseRedisService redisService;

    @RequestMapping("/socket")
    public String login(@RequestParam("data") String data){
        String s = SocketBase.successWebSocket(data, "system");
        try {
            messageWebSocket.sendAllSocketMessage(s);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "success";
    }

    @RequestMapping("/addRedis")
    public String addRedis(){
        redisService.set("liuxin","123456",60*5*1000);
        return "success";
    }

    @RequestMapping("/getRedis")
    public String getRedis(){
        String liuxin = (String) redisService.get("liuxin");
        return liuxin;
    }
}
